package com.kawaiior.asoulworld.capability;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.INBTSerializable;

import java.util.LinkedList;
import java.util.Queue;

public class AsoulTimePower implements INBTSerializable<NBTTagCompound> {

    private int time_length = 8;
    private Queue<int[]> posQueue = new LinkedList<int[]>();
    private Queue<Integer> healthQueue = new LinkedList<Integer>();

    private int asoulTimeCool = 0;

    private int[] playerHealth = new int[]{-1, -1, -1, -1, -1, -1, -1, -1};

    public void setHot(){
        this.asoulTimeCool = 59;
    }

    public boolean isHot(){
        return this.asoulTimeCool > 0;
    }

    public void coolAsoulTime(){
        if (this.asoulTimeCool>0){
            this.asoulTimeCool--;
        }
    }

    public int getCool(){
        return this.asoulTimeCool;
    }

    public int getPlayerHealth() {

        Integer h = healthQueue.peek();
        if (h == null){
            return -1;
        }
        return h;
    }

    public void setPlayerHealth(int playerHealth){

        if (this.healthQueue.size() >= this.time_length){
            this.healthQueue.poll();
        }
        this.healthQueue.offer(playerHealth);
    }

    public int[] getTime(){
        return this.posQueue.peek();
    }

    public void setTime(int[] posArray){

        if (this.posQueue.size() >= this.time_length){
            this.posQueue.poll();
        }
        this.posQueue.offer(posArray);
    }

    public void setAllTime(int[] posArray){
        this.posQueue.offer(posArray);
    }

    @Override
    public NBTTagCompound serializeNBT() {
        NBTTagCompound nbt = new NBTTagCompound();

        nbt.setIntArray("AsoulTime0", this.getTime());

        nbt.setInteger("AsoulTimeC", this.asoulTimeCool);
        nbt.setIntArray("AsoulTimeH", this.playerHealth);

        return nbt;
    }

    @Override
    public void deserializeNBT(NBTTagCompound nbt) {
        this.setTime(nbt.getIntArray("AsoulTime0"));

        this.asoulTimeCool = nbt.getInteger("AsoulTimeC");
        this.playerHealth = nbt.getIntArray("AsoulTimeH");
    }
}
